#include "palette.h"

#include <QtCore/QVariant>

using namespace core;

Palette::Palette(const QColor& border, const QColor& foreground,
    const QColor& background, const QColor& whole, const QColor& selection,
    const QColor& transformation, const QColor& acceptsConnection,
    const QColor& deniesConnection) :
    m_borderColor(border),
    m_foregroundColor(foreground),
    m_backgroundColor(background),
    m_wholeColor(whole),
    m_selectionColor(selection),
    m_transformationColor(transformation),
    m_acceptsConnectionColor(acceptsConnection),
    m_deniesConnectionColor(deniesConnection)
{
}

Palette::~Palette()
{

}

QColor Palette::borderColor() const
{
    return m_borderColor;
}

QColor Palette::foregroundColor() const
{
    return m_foregroundColor;
}

QColor Palette::backgroundColor() const
{
    return m_backgroundColor;
}

QColor Palette::wholeColor() const
{
    return m_wholeColor;
}

QColor Palette::selectionColor() const
{
    return m_selectionColor;
}

QColor Palette::transformationColor() const
{
    return m_transformationColor;
}

QColor Palette::acceptsConnectionColor() const
{
    return m_acceptsConnectionColor;
}

QColor Palette::deniesConnectionColor() const
{
    return m_deniesConnectionColor;
}

Palette* Palette::defaultPalette()
{
    Palette* ret = new Palette(QColor(0, 0, 0), QColor(0, 0, 0),
        QColor(255, 255, 255), QColor(0, 0, 0), QColor(44, 173, 210),
        QColor(44, 173, 210), QColor(44, 210, 79), QColor(210, 56, 44));

    return ret;
}

bool Palette::doActionForProperty(const QString& property,
    const QVariantList& value, const SerializationEngine& helper)
{
    bool ret = true;

    if (property == "borderColor")
    {
        m_borderColor = value.first().value<QColor>();
    }
    else if (property == "foregroundColor")
    {
        m_foregroundColor = value.first().value<QColor>();
    }
    else if (property == "backgroundColor")
    {
        m_backgroundColor = value.first().value<QColor>();
    }
    else if (property == "wholeColor")
    {
        m_wholeColor = value.first().value<QColor>();
    }
    else if (property == "selectionColor")
    {
        m_selectionColor = value.first().value<QColor>();
    }
    else if (property == "transformationColor")
    {
        m_transformationColor = value.first().value<QColor>();
    }
    else if (property == "acceptsConnectionColor")
    {
        m_acceptsConnectionColor = value.first().value<QColor>();
    }
    else if (property == "deniesConnectionColor")
    {
        m_deniesConnectionColor = value.first().value<QColor>();
    }

    return ret;
}

void Palette::deserializationFinished(bool ok)
{

}

QHash<QString, QVariantList> Palette::serializationData(
    const SerializationEngine& helper) const
{
    QHash<QString, QVariantList> ret;

    QVariantList list;

    list.append(QVariant(m_borderColor));

    ret["borderColor"] = list;

    list.clear();

    list.append(QVariant(m_foregroundColor));

    ret["foregroundColor"] = list;

    list.clear();

    list.append(QVariant(m_backgroundColor));

    ret["backgroundColor"] = list;

    list.clear();

    list.append(QVariant(m_wholeColor));

    ret["wholeColor"] = list;

    list.clear();

    list.append(QVariant(m_selectionColor));

    ret["selectionColor"] = list;

    list.clear();

    list.append(QVariant(m_transformationColor));

    ret["transformationColor"] = list;

    list.clear();

    list.append(QVariant(m_acceptsConnectionColor));

    ret["acceptsConnectionColor"] = list;

    list.clear();

    list.append(QVariant(m_deniesConnectionColor));

    ret["deniesConnectionColor"] = list;

    list.clear();

    return ret;
}
